﻿@{ ViewBag.Title = "Add";
    Layout = "~/Areas/Shared/_LayoutFile.cshtml"; }

<input style="display:none" id="tbid" value="@ViewBag.tbid">
<input style="display:none" id="indexid" value="@ViewBag.indexid">
<input style="display:none" id="from" value="@ViewBag.from">
<input style="display:none" id="src" value="@ViewBag.src">
<input style="display:none" id="filename"  value="@ViewBag.fname">
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-input-block" style="text-align: center;margin-top: 20px;">
            <button class="layui-btn" id="btn_Upload">
                <i class="layui-icon layui-icon-upload"></i>上传图片
            </button>
            <button class="layui-btn" lay-submit lay-filter="btn_OK" id="btn_OK">确定</button>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-input-block" align="center">
            <div class="layui-upload-list">
                <img id="F_Img" height="300" src='@ViewBag.src'/>
                <p id="demoText"></p>
            </div>
        </div>
    </div>
</div>

@section Scripts
{
    <script type="text/javascript">
        layui.use(['form', 'layer', 'upload'], function () {
            let $ = layui.$;
            let upload = layui.upload;
            let layer = layui.layer;
            let form = layui.form;

            upload.render({
                elem: '#btn_Upload',
                field: 'file',
                url: '@Url.Action("ImgUplaod")',
                auto: true,
                exts: 'jpg|gif|png|jpeg|',
                done: function (res) {
                    if (res.code == 0) {
                        $("#src").val(res.src);
                        $("#F_Img").attr("src", res.src);
                        $("#filename").val(res.filename);

                        getVal();
                    }
                },
                error: function () {
                    layer.alert('上传失败', {
                        icon: 2
                    });
                }
            });

            $('#btn_OK').on('click', function () {
                getVal();
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            });

            function getVal() {
                $(window.parent.document).find('#' + $("#indexid").val()).attr('src', $("#src").val());
                $(window.parent.document).find('#' + $("#indexid").val()).attr('alt', $("#filename").val());
                $(window.parent.document).find('#' + $("#indexid").val() + '_Exa').val($("#filename").val());
            }

        });
    </script>

}